import React from 'react';
import { connect } from 'react-redux';
import $ from 'jquery';

class Child_jt_s extends React.Component{

	componentDidMount() {
		console.log(11);
        this.props.getData();
    }
	render(){
		var items=this.props.list.map(function(item,index){
			return(
				<li key={index}>
					<h3>{item.title}</h3>
					<img src={item.img} alt="sb"/>
				</li>
			)
		})
		return(
			<ul>
				{items}
			</ul>
		)
	}
}

const mapStateToProps =function(state){
	return{
		list:state.list
	}
}

const mapDispatchToProps=function(dispatch){
	return{
		getData:function(dispath,getState){
			$.get('http://route.showapi.com/341-2',{
				 showapi_appid: 26444,
                 showapi_sign: 'e6ed68d43d734b78892a649fedd90cbe',
                 maxResult: 8
			},function(res){
				dispatch({
					type:'GET_DATA',
					list:res.showapi_res_body.contentlist
				})
			})
		}
	}
}

var Child_jt=connect(
		mapStateToProps,
		mapDispatchToProps
)(Child_jt_s);

export default Child_jt;